# syntax=docker/dockerfile:1.4

 FROM alpine:3.16 as build

 # 如果有问题把上下的这句都给去掉，--mount
 #RUN --mount=type=cache,target=/var/cache/apk
 RUN  sed -i 's/dl-cdn.alpinelinux.org/mirrors.tencent.com/g' /etc/apk/repositories &&  \
     apk update && \
     apk add gcompat gcc g++ make musl && \
     apk add hiredis-dev rabbitmq-c-dev  mysql-dev && \
     apk add --no-cache nlohmann-json 

 WORKDIR /build

 COPY   ./core .

#  RUN mkdir -p /usr/share/man/man1 &&\
#      cp ./sim/sim.1 /usr/share/man/man1/sim.1 &&\
#      apk add flex &&\
#      make -B sim 
    #  配合下面COPY，编译And拷贝可执行文件
     

 RUN make judged

 FROM alpine:3.16 as image

 WORKDIR /app

 #RUN --mount=type=cache,target=/var/cache/apk
 RUN   sed -i 's/dl-cdn.alpinelinux.org/mirrors.tencent.com/g' /etc/apk/repositories &&  \
     apk update && \
     apk add g++ gcc python3  &&\
     apk add hiredis rabbitmq-c  mysql-dev && \
     apk add --no-cache nlohmann-json &&\
     apk add diffutils 

# RUN apk add openjdk17 
#这个总是拉取不成功，单独做镜像层

 COPY --from=build /build/judged /app/judged

#  COPY --from=build /usr/bin/sim_* /app/

 ENTRYPOINT ["/app/judged"]

# 调试版本
# FROM alpine:3.16 as build

# # 如果有问题把上下的这句都给去掉，--mount
# #RUN --mount=type=cache,target=/var/cache/apk


# RUN  sed -i 's/dl-cdn.alpinelinux.org/mirrors.tencent.com/g' /etc/apk/repositories &&  \
#    apk update && \
#    apk add gcompat gcc g++ make musl && \
#     apk add hiredis-dev rabbitmq-c-dev  mysql-dev && \
#    apk add --no-cache nlohmann-json &&\
#    apk add gdb flex

# # RUN apk add openjdk17 

# WORKDIR /build

# COPY   ./core .

# RUN make judged

# COPY  ./config/config.conf ./config.conf


# RUN mkdir -p /usr/share/man/man1 &&\
#      cp ./sim/sim.1 /usr/share/man/man1/sim.1 &&\
#      make -B sim 
# # ENTRYPOINT ./judged 

# ENTRYPOINT tail -f /dev/null
